package emulator.util;


public class MemoryPtr {
	
	private byte [] memory;
	private int offset;

	public MemoryPtr(byte[] memory, int offset)
	{
		this.memory = memory;
		this.offset = offset;
	}
	
	public void get(byte[] raw_bytes) {
		for (int i = 0; i < raw_bytes.length; i++)
			raw_bytes[i] = memory[i+offset];
	}

	public int getWordOp() {
//		return memory[offset+1] + (((int)memory[offset+2]) << 8);
		return (memory[offset+1] & 0xFF) + ((memory[offset+2] & 0xFF) << 8);
	}

	public int getByteOp() {
		return memory[offset+1] & 0xFF;
	}

	public int getRelativeOp() {
		int jumprel = getByteOp();
		if (jumprel > 127)
			jumprel -= 256;
		return offset+2+jumprel;
	}
}
